package audio;

import java.io.File;
import java.io.Serializable;
import java.util.Vector;

public abstract class AudioFile implements Serializable {

	protected File file;

	protected String formatedDuration = "00:00";

	protected String genre;

	protected String title;

	protected String artist;

	protected String album;

	protected int track = -1;

	public AudioFile(File file) {
		this.file = file;
		genre = "";
		title = "";
		artist = "";
		album = "";
	}

	public Boolean contains(String text) {
		String s = text.toLowerCase();
		return (file.toString().toLowerCase().contains(s)
				|| genre.toLowerCase().contains(s)
				|| title.toLowerCase().contains(s)
				|| artist.toLowerCase().contains(s) || album.toLowerCase()
				.contains(s));
	}

	public String toString() {

		return file.toString();
	}

	public File getFile() {
		return file;
	}

	public String getType() {
		return "mp3";
	}

	public static boolean isAudioFile(String s) {
		try {
			String extension = s.substring(s.lastIndexOf(".")).toLowerCase();
			if (extension.equals(".mp3")) {
				return true;
			} else {
				System.out.println(s + " n'est pas un mp3");
				return false;

			}
		} catch (Exception e) {
			return false;
		}
	}

	public static boolean isAudioFile(File f) {
		return isAudioFile(f.getAbsolutePath());

	}

	/**
	 * Get Sampling Rate
	 * 
	 * @return sampling rate
	 */
	abstract public int getSamplingRate();

	/**
	 * Get Nominal Bitrate
	 * 
	 * @return bitrate in bps
	 */
	public String getFormatedDuration() {
		return formatedDuration;
	}

	abstract public int getBitRate();

	/**
	 * Get channels.
	 * 
	 * @return channels
	 */
	abstract public int getChannels();

	/**
	 * Get play time in seconds.
	 * 
	 * @return play time in seconds
	 */
	abstract public long getPlayTime();

	/**
	 * Get the title of the song.
	 * 
	 * @return the title of the song
	 */
	abstract public String getTitle();

	/**
	 * Get the artist that performed the song
	 * 
	 * @return the artist that performed the song
	 */
	abstract public String getArtist();

	/**
	 * Get the name of the album upon which the song resides
	 * 
	 * @return the album name
	 */
	abstract public String getAlbum();

	/**
	 * Get the track number of this track on the album
	 * 
	 * @return the track number
	 */
	abstract public int getTrack();

	/**
	 * Get the genre string of the music
	 * 
	 * @return the genre string
	 */
	abstract public String getGenre();

	/**
	 * Get the year the track was released
	 * 
	 * @return the year the track was released
	 */
	abstract public String getYear();

	/**
	 * Get any comments provided about the song
	 * 
	 * @return the comments
	 */
	abstract public Vector getComment();

	public void setGenre(String genre) {
		this.genre = genre;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setArtist(String artist) {
		this.artist = artist;
	}

	public void setAlbum(String album) {
		this.album = album;
	}

	public void setTrack(int track) {
		this.track = track;
	}

	public void setTrack(String track) {
		this.track = Integer.parseInt(track);
	}

}
